<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	xmlns:pe="http://primefaces.org/ui/extensions">
	template="/WEB-INF/templates/template.xhtml">
	<ui:define name="content">


<pe:masterDetail id="masterDetail" selectLevelListener="#{selectLevelListener.handleNavigation}"
                 showAllBreadcrumbItems="true">
    <f:facet name="header">
        <p:messages showDetail="false" showSummary="true"/>
    </f:facet>

    <pe:masterDetailLevel level="1">
        <f:facet name="label">
            <h:outputFormat value="Overview {0}">
                <f:param value="Clientes"/>
            </h:outputFormat>
        </f:facet>

        <p:dataTable id="persons" value="#{complexMasterDetailController.clientes}" var="pers">
            <p:column headerText="Name">
                <p:commandLink value="#{pers.apellido}">
                    <pe:selectDetailLevel contextValue="#{pers}"/>
                </p:commandLink>
            </p:column>
            <p:column headerText="Nombres">
                <h:outputText value="#{pers.nombres}"/>
            </p:column>
            <p:column headerText="Direccion">
                <h:outputText value="#{pers.direccion}"/>
                    
            </p:column>
        </p:dataTable>
    </pe:masterDetailLevel>

    <pe:masterDetailLevel level="2" contextVar="cliente" levelLabel="Person Detail">
        <h:panelGrid id="personDetail" columns="2" columnClasses="formColumn1,formColumn2">
            <h:outputText value="Apellido (string)"/>
            <p:inputText value="#{person.Apellido}" required="true" label="Apellido"/>
            <h:outputText value="Nombres (string)"/>
            <p:inputText value="#{person.nombres}" required="true" label="Nombres"/>
            <h:outputText value="Direccion (string)"/>
            <p:inputText value="#{person.direccion}" required="true" label="Direccion"/>

        </h:panelGrid>

        <p:commandButton value="Save with success" process="masterDetail"
                         action="#{complexMasterDetailController.saveSuccess(person)}"
                         style="margin-top:10px;" icon="ui-icon-disk">
            <pe:selectDetailLevel level="1"/>
        </p:commandButton>
        <p:commandButton value="Save with failure" process="masterDetail"
                         action="#{complexMasterDetailController.saveFailure(person)}"
                         style="margin-top:10px;" icon="ui-icon-disk">
            <pe:selectDetailLevel level="1"/>
        </p:commandButton>
        <p:commandButton type="button" value="Delete" onclick="PF('deletedDlg').show()" style="margin-top:10px;"/>

        <p:dialog header="Delete confirmation" widgetVar="deletedDlg" resizable="false">
            <h:panelGroup layout="block" style="padding:5px;">
                <h:outputText value="Are you sure you want to delete this person?"/>
            </h:panelGroup>
            <p:commandButton id="deleteBtn" value="Delete" oncomplete="PF('deletedDlg').hide();"
                             action="#{complexMasterDetailController.delete(person)}" process="@this"
                             style="margin-top:10px;">
                <pe:selectDetailLevel level="1"/>
            </p:commandButton>
            <p:commandButton value="Cancel" type="button" onclick="PF('deletedDlg').hide();"
                             style="margin-top:10px;"/>
        </p:dialog>
    </pe:masterDetailLevel>
</pe:masterDetail>

            